package com.example.demo.FactoryPattern;

import java.lang.reflect.Constructor;

/**
 * @author gyq
 * @description
 * @datetime 2019/2/23 20:20
 */
public class HairFactory {
    public HairInterface getHair(String key) {
        try {
            Class dClass = Class.forName("com.example.demo.FactoryPattern." + key + "Hair");
            Constructor c = dClass.getConstructor();
            return (HairInterface) c.newInstance();
        } catch (Exception e) {
            return null;
        }
    }
}
